package br.com.sjdr.projeto.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JTextField;

import br.com.sjdr.projeto.menu.MenuLoogin;

public class TelaLogin implements ActionListener {

	// Declarando o frame
	JFrame frame = new JFrame("SJDR CONFECOES - Login -");
	JPanel panelAdm = new JPanel();
	JMenuBar menuBar = new JMenuBar();

	JButton desligar = new JButton("Encerrar");
	JButton adm = new JButton("Administrador");
	JButton ven = new JButton("Vendedor");
	JButton cli = new JButton("Cliente");
	
	JLabel logo = new JLabel();
	JTextField t1 = new JTextField("Usuario");
	JTextField t2 = new JTextField("Senha");
	JLabel login = new JLabel("LOGIN");

	public void login() {

		/**
		 * Tela respopnsavel por login de Usuarios
		 * Ou quando usuario efetua louout
		 */
		
		
		// Definindo o frame
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(800, 600); // Tamanho do frame
		frame.setVisible(true); // Frame visivel ou nao

		frame.setResizable(false);
		
		// Centraliza a janela.
		java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit()
				.getScreenSize();
		int componentWidth = frame.getWidth();
		int componentHeight = frame.getHeight();
		frame.setBounds((screenSize.width - componentWidth) / 2,
				(screenSize.height - componentHeight) / 4, componentWidth,
				componentHeight);

		logo.setIcon(new ImageIcon("logosjdr.jpg"));
		
		// Botões

		adm.setMaximumSize(screenSize);
		menuBar.add(adm);
		adm.addActionListener(this);

		ven.setMaximumSize(screenSize);
		menuBar.add(ven);
		ven.addActionListener(this);

		cli.setMaximumSize(screenSize);
		menuBar.add(cli);
		cli.addActionListener(this);

		desligar.setMaximumSize(screenSize);
		menuBar.add(desligar);
		desligar.addActionListener(this);

		// LOGIN
		
		t1.setSize(200, 25);
		t1.setLocation(300, 270);
		t1.setFont(new java.awt.Font("arial", 1, 14));
		t1.setEnabled(true);
		frame.add(t1);

		t2.setSize(200, 25);
		t2.setLocation(300, 300);
		t2.setFont(new java.awt.Font("arial", 1, 14));
		t2.setEnabled(true);
		frame.add(t2);

		// Adicionando componentes ao painel
		frame.setBackground(Color.white); // cordo painel
		menuBar.setVisible(true);
		frame.setJMenuBar(menuBar);
		frame.getContentPane().add(BorderLayout.NORTH, panelAdm); // Adicionando
		// painel
		frame.getContentPane().add(BorderLayout.CENTER, logo); // Adicionado
		// logo
		
		

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();
		String login = t1.getText();//Pegando valores do label LOGIN
		String senha = t2.getText();//Pegando valores do label SENHA
		
		if (source == desligar) {
			try {

			} catch (Exception e2) {

			}
			MenuLoogin.metodosdeSaida();

		}
		if (source == adm) {
			try {
				frame.setVisible(false);
			} catch (Exception e2) {

			}
			new TelaAdministrador();

		}
		if (source == ven) {
			try {
				frame.setVisible(false);
			} catch (Exception e2) {

			}
			TelaVendedor t = new TelaVendedor();
			t.go();

		}
		if (source == cli) {
			try {
				frame.setVisible(false);
			} catch (Exception e2) {

			}

			TelaComprador t = new TelaComprador();
			t.goComp();

		}

	}

}